﻿using TriplesProblems;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Collections;

namespace TripleTests
{
    [TestClass()]
    public class TripleTest
    {
        [TestMethod()]
        public void TripleConstructorEmptyTest()
        {
            Triple empty = new Triple();
            Assert.IsTrue(empty[0] == 0 && empty[1] == 0 && empty[2] == 0);
        }

        [TestMethod()]
        public void TripleConstructorTest1()
        {
            Triple target = new Triple(2, 10, -9);
            Assert.IsTrue(target[0] == 2 && target[1] == 10 && target[2] == -9);
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void CloneNullReferenceTest()
        {
            Triple original = null;
            Triple clone = original.Clone() as Triple;
        }

        [TestMethod()]
        public void CloneDifferentReferencesTest()
        {
            Triple original = new Triple(2,3,6);
            Triple clone = original.Clone() as Triple;
            Assert.AreNotSame(clone, original);
        }

        [TestMethod()]
        public void CloneAreEqualTest()
        {
            Triple original = new Triple(2, 3, 6);
            Triple clone = original.Clone() as Triple;
            Assert.IsTrue(original.CompareTo(clone) == 0);
        }

        [TestMethod()]
        public void CloneDeepCopyTest()
        {
            Triple original = new Triple(2, 3, 6);
            Triple clone = original.Clone() as Triple;
            original[2]++;
            Assert.AreNotEqual(clone, original);
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void CompareToNullReferenceThisTest()
        {
            Triple triple = null;
            Triple other = new Triple();
            triple.CompareTo(other);
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void CompareToNullReferenceOtherTest()
        {
            Triple triple = null;
            Triple other = new Triple();
            other.CompareTo(triple);
        }

        [TestMethod()]
        public void CompareToBiggerTest()
        {
            Triple first = new Triple(5,6,7);
            Triple second = new Triple(1,2,3);
            Assert.IsTrue(first.CompareTo(second) > 0);
        }

        [TestMethod()]
        public void CompareToSmallerTest()
        {
            Triple first = new Triple(-5, 1, 1);
            Triple second = new Triple(1, 2, 3);
            Assert.IsTrue(first.CompareTo(second) < 0);
        }

        [TestMethod()]
        public void CompareToEqualTest()
        {
            Triple first = new Triple(-1, 1, 1);
            Triple second = new Triple(1, -1, 1);
            Assert.IsTrue(first.CompareTo(second) == 0);
        }

        [TestMethod()]
        public void ExtractTriplesFromTextFileTest()
        {
            string path = @"C:\Users\The Damage\Documents\visual studio 2010\Projects\SampleIntermediateExam1\TriplesProblems\bin\Debug\input.txt";
            string expected = "{(1, 2, 3);(22, 33, 44);(1, 2, 3)}";
            string actual = Triple.ExtractTriplesFromTextFile(path).AsString();
            Assert.AreEqual(expected, actual);
        }

       

        [TestMethod()]
        public void GetValuesSumTest()
        {
            int element = 6;
            Triple target = new Triple(element, element, element);
            int expectedElementsSum = element*3;
            int actual = target.GetValuesSum();
            Assert.AreEqual(expectedElementsSum, actual);
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void GetValuesSumNullReferenceTest()
        {
            Triple target = null;
            int actual = target.GetValuesSum();
        }

        [TestMethod()]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void IndexerGetOutOfRangeTest()
        {
            Triple target = new Triple(1,2,3);
            int i = target[-1];
        }

        [TestMethod()]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void IndexerGetOutOfRangeTest2()
        {
            Triple target = new Triple(1, 2, 3);
            int i = target[5];
        }

        [TestMethod()]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void IndexerSetOutOfRangeTest()
        {
            Triple target = new Triple(1, 2, 3);
            target[-1] = 5;
        }

        [TestMethod()]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void IndexerSetOutOfRangeTest2()
        {
            Triple target = new Triple(1, 2, 3);
            target[6] = 169;
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void IndexerGetNullReferenceTest()
        {
            Triple target = null;
            int i = target[5];
        }

        [TestMethod()]
        [ExpectedException(typeof(NullReferenceException))]
        public void IndexerSetNullReferenceTest()
        {
            Triple target = null;
            target[5] = 6;
        }

        ///// <summary>
        /////A test for System.Collections.IEnumerable.GetEnumerator
        /////</summary>
        //[TestMethod()]
        //[DeploymentItem("TriplesProblems.dll")]
        //public void GetEnumeratorTest1()
        //{
        //    IEnumerable target = new Triple(); // TODO: Initialize to an appropriate value
        //    IEnumerator expected = null; // TODO: Initialize to an appropriate value
        //    IEnumerator actual;
        //    actual = target.GetEnumerator();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        [TestMethod()]
        public void ToStrinTest()
        {
            Triple target = new Triple(2, 3, 4);
            string expected = "(2, 3, 4)";
            string actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void op_AdditionTest()
        {
            Triple triple = new Triple(1, 2, 3);
            Triple triple2 = new Triple(1, 2, 5);
            Triple expected = new Triple(2, 4, 8);
            Triple actual = triple + triple2;
            Assert.IsTrue(expected.CompareTo(actual) == 0);
        }

        [TestMethod()]
        public void op_IncrementTest()
        {
            Triple triple = new Triple(1, 2, 3);
            triple++;
            Triple expected = new Triple(2, 3, 4);
            Assert.IsTrue(expected.CompareTo(triple) == 0);
        }

        [TestMethod()]
        public void op_SubtractionTest()
        {
            Triple triple = new Triple(1, 2, 3);
            Triple triple2 = new Triple(1, 2, 5);
            Triple expected = new Triple(0, 0, 2);
            Triple actual = triple2 - triple;
            Assert.IsTrue(expected.CompareTo(actual) == 0);
        }
    }
}
